﻿using Logic;
using UnityEngine;

namespace Bullet
{
    public class BulletDamage : MonoBehaviour
    {
        public float Damage { get; set; }
        [SerializeField] private BulletMove _move;
        private bool _collided;

        private void OnTriggerEnter(Collider other)
        {
            if (other.CompareTag(Constants.PlayerTag)) return;
            if (_collided) 
                return;
            if (!other.TryGetComponent<IHealth>(out var health)) 
                return;
            _collided = true;
            health.TakeDamage(Damage);
            _move.IsAlive = false;
            Destroy(gameObject);
        }
    }
}